<?php declare(strict_types=1);

/**
 * @author      guosir
 * @copyright   2023-2025 owner
 **/

namespace Srv\Apps\Apis\Develop\Ctl;

use Srv\Apps\Proto\DTO\Develop\GlobalConfAddDTO;
use Srv\Apps\Proto\DTO\Develop\GlobalConfEditDTO;
use Srv\Apps\Proto\DTO\Develop\GlobalConfListDTO;
use Srv\Apps\Proto\Enum\BannerShowStyleEnum;
use Srv\Apps\Proto\Enum\YesOrNoEnum;
use Srv\Apps\Proto\VO\Develop\AppAdDayLimitVO;
use Srv\Apps\Proto\VO\Develop\AppAdMaxConfVO;
use Srv\Apps\Proto\VO\Develop\AppAdMaxVO;
use Srv\Apps\Proto\VO\Develop\AppAdMobConfVO;
use Srv\Apps\Proto\VO\Develop\AppAdMobVO;
use Srv\Apps\Proto\VO\Develop\AppAdOpenVO;
use Srv\Apps\Proto\VO\Develop\AppAdSplitTimeVO;
use Srv\Apps\Proto\VO\Develop\AppAdUnlockSetVO;
use Srv\Apps\Proto\VO\Develop\AppBannerShowStyleVO;
use Srv\Apps\Proto\VO\Develop\AppCoinUnlockSetVO;
use Srv\Apps\Proto\VO\Develop\AppDesktopRewardVO;
use Srv\Apps\Proto\VO\Develop\AppGlobalConfVO;
use Srv\Apps\Proto\VO\Develop\AppPayRechargeTextVO;
use Srv\Apps\Proto\VO\Develop\AppPayRechargeVO;
use Srv\Apps\Proto\VO\Develop\AppPayVipVO;
use Srv\Apps\Proto\VO\Develop\AppRechargeRetainItemVO;
use Srv\Apps\Proto\VO\Develop\AppRechargeRetainVO;
use Srv\Apps\Proto\VO\Develop\AppReviewFeedbackVO;
use Srv\Apps\Proto\VO\Develop\AppRmdAdPosVO;
use Srv\Apps\Proto\VO\Develop\AppTaskConfVO;
use Srv\Apps\Proto\VO\Develop\AppVipUnlockSetVO;
use Srv\Apps\Proto\VO\Develop\GlobalConfListVO;
use Srv\Apps\Proto\VO\Develop\GlobalConfVO;
use Srv\Libs\Common\CommArray;
use Srv\Libs\Common\CommJson;
use Srv\Libs\Common\CommTime;
use Srv\Libs\Frame\ControllerAbstract;
use Srv\Libs\Frame\Page;
use Srv\Libs\Storage\DataMysql;

final class GlobalConfCtl extends ControllerAbstract
{
    private ?DataMysql $DbAuto                  = null;                         // DB-Write
    public const KEY_APP_PRIVACY_VERSION        = 'app_privacy_version';        // 应用隐私版本[0-不提醒,APP小于该版本则提醒]
    public const KEY_APP_PRIVACY_URL            = 'app_privacy_url';            // 隐私政策地址URL
    public const KEY_APP_PRIVACY_URL_IOS        = 'app_privacy_url_ios';        // 隐私政策地址URL[iOS]
    public const KEY_APP_REGISTER_URL           = 'app_register_url';           // 注册协议地址URL
    public const KEY_APP_REGISTER_URL_IOS       = 'app_register_url_ios';       // 注册协议地址URL[iOS]
    public const KEY_APP_AUTHORITY_URL          = 'app_authority_url';          // 应用功能权限说明URL
    public const KEY_APP_CHILD_PROTECT_URL      = 'app_child_protect_url';      // 儿童保护政策URL
    public const KEY_APP_CONTACT_SERVICE_URL    = 'app_contact_service_url';    // 联系客服URL
    public const KEY_APP_PAY_SERVICE_URL        = 'app_pay_service_url';        // 支付服务协议URL
    public const KEY_APP_SMS_CHECK              = 'app_sms_check';              // 是否严格校验手机号[0-否,1-是]
    public const KEY_APP_SMS_SEND               = 'app_sms_send';               // 短信发送状态[0-否,1-是]
    public const KEY_APP_SMS_DEBUG              = 'app_sms_debug';              // 短信调试验证码[仅开发环境使用]
    public const KEY_APP_AVATAR_USER_ALL        = 'app_avatar_user_all';        // 用户默认头像[无性别]
    public const KEY_APP_AVATAR_USER_MAN        = 'app_avatar_user_man';        // 用户默认头像[男]
    public const KEY_APP_AVATAR_USER_WOMAN      = 'app_avatar_user_woman';      // 用户默认头像[女]
    public const KEY_VERSION_GLOBAL_CONFIG      = 'version_global_config';      // 版本配置-全局配置
    public const KEY_APP_IMAGE_PREFIX_URL       = 'app_image_prefix_url';       // 应用图片前缀URL[结尾无/]
    public const KEY_APP_FILE_PREFIX_URL        = 'app_file_prefix_url';        // 应用文件前缀URL[结尾无/]
    public const KEY_APP_EMAIL_CHECK            = 'app_email_check';            // 是否检查邮件黑名单地址[0-否,1-是]
    public const KEY_APP_EMAIL_SEND             = 'app_email_send';             // 邮件发送状态[0-否,1-是]
    public const KEY_APP_EMAIL_DEBUG            = 'app_email_debug';            // 邮件调试验证码[仅开发环境使用]
    public const KEY_PROJECT_URL                = 'project_url';                // 项目网站地址URL[可空]
    public const KEY_COMPANY_URL                = 'company_url';                // 公司网站地址URL[可空]
    public const KEY_APP_IOS_REVIEW_VERSION     = 'app_ios_review_version';     // iOS审核版本[1.0.1]
    public const KEY_AD_OPEN_SET                = 'ad_open_set';                // 开屏广告;status:启用[0-否,1-是];showType:[1-随机,2-轮循][1];splitTime:恢复间隔时长[秒][30][0-3600]
    public const KEY_APP_DISABLE_REGISTER       = 'app_disable_register';       // 禁止注册状态[0-否,1-是]
    public const KEY_APP_DISABLE_SIGN_IN        = 'app_disable_sign_in';        // 禁止登入状态[0-否,1-是]
    public const KEY_APP_AD_OPEN                = 'app_ad_open';                // 应用开屏SDK广告启停状态[0-否,1-是]
    public const KEY_SKIT_AD_UNLOCK_SET         = 'skit_ad_unlock_set';         // 短剧广告解锁status:启用[0-否,1-是];unlockNum:[解锁集数][3]
    public const KEY_APP_PAY_TEXT_RECHARGE      = 'app_pay_text_recharge';      // 支付充值看点的提示文案
    public const KEY_APP_PAY_RECHARGE           = 'app_pay_recharge';           // 应用内充值支付入口启停状态[0-否,1-是]
    public const KEY_APP_PAY_VIP                = 'app_pay_vip';                // 应用内VIP购买入口启停状态[0-否,1-是]
    public const KEY_SKIT_BUY_UNLOCK_SET        = 'skit_buy_unlock_set';        // 短剧付费解锁status:启用[0-否,1-是]
    public const KEY_SKIT_VIP_UNLOCK_SET        = 'skit_vip_unlock_set';        // 短剧VIP解锁status:启用[0-否,1-是]
    public const KEY_APP_BANNER_SHOW_STYLE      = 'app_banner_show_style';      // 应用Banner显示样式[1-样式1,2-样式2]
    public const KEY_APP_TASK_STATUS            = 'app_task_status';            // 任务开关[0-关,1-开]
    public const KEY_APP_AD_MOB_CONF            = 'app_ad_conf_mob';            // 应用广告Mob
    public const KEY_APP_RECHARGE_RETAIN        = 'app_recharge_retain';        // 充值挽留数据,status-启停状态[0-否,1-是],title-标题,desc-描述,dayNum-间隔周期[天][0-不间隔]

    public const KEY_APP_RMD_AD_POS             = 'app_rmd_ad_pos';             // 推荐列表广告位配置,status-启停状态[0-否,1-是],posList-位置数数组
    public const KEY_APP_REVIEW_FEEDBACK        = 'app_review_feedback';        // 反馈评价配置,status-启停状态[0-否,1-是],title-标题,desc-描述,playSeriesNum-引导观看过N集[0-N],starNum-好评分数配置[0-5],rewardNum-奖励数,rewardTime-奖励时长[秒]
    public const KEY_APP_DESKTOP_REWARD         = 'app_desktop_reward';         // 添加桌面的奖励配置,status-启停状态[0-否,1-是],rewardNum-奖励数,rewardTime-奖励时长[秒]

    public const KEY_APP_AD_SPLIT_TIME          = 'app_ad_split_time';          // 每个广告间隔时长[秒][0-不限制]
    public const KEY_APP_AD_DAY_LIMIT           = 'app_ad_day_limit';           // 每个用户每天广告次数[0-不限制]
    public const KEY_APP_AD_MAX_CONF            = 'app_ad_conf_max';            // 应用广告Max

    // appGlobalKeyList
    private array $appGlobalKeyList             = [
        self::KEY_APP_AD_OPEN,
        self::KEY_SKIT_AD_UNLOCK_SET,
        self::KEY_SKIT_VIP_UNLOCK_SET,
        self::KEY_SKIT_BUY_UNLOCK_SET,
        self::KEY_APP_PAY_TEXT_RECHARGE,
        self::KEY_APP_PAY_VIP,
        self::KEY_APP_PAY_RECHARGE,
        self::KEY_APP_BANNER_SHOW_STYLE,
        self::KEY_APP_TASK_STATUS,
        self::KEY_APP_AD_MOB_CONF,
        self::KEY_APP_RECHARGE_RETAIN,
        self::KEY_APP_RMD_AD_POS,
        self::KEY_APP_REVIEW_FEEDBACK,
        self::KEY_APP_DESKTOP_REWARD,
        self::KEY_APP_AD_SPLIT_TIME,
        self::KEY_APP_AD_DAY_LIMIT,
        self::KEY_APP_AD_MAX_CONF
    ];

    /**
     * @return static
     * tag
     */
    final public static function tag():self
    {
        $thisObject                         = self::tagGet();
        if($thisObject instanceof self){
            $thisObject->DbAuto             = self::getDbAuto();
        }
        return $thisObject;
    }

    /**
     * @param int $stgsId
     * @return array
     * getGlobalConfSrc
     */
    public function getGlobalConfSrc(int $stgsId):array
    {
        if($stgsId < 1) return [];
        $isFail         = false;
        $globalConfSrc  = $this->DbAuto->getDataOne('SELECT stgs_id, user_id, stgs_key, stgs_value, stgs_desc, stgs_create_time, stgs_update_time FROM '.$this->DbAuto->getTableNameAll('conf_globals').' WHERE stgs_id='.$stgsId.' AND stgs_delete=0', $isFail);
        if($isFail || !isset($globalConfSrc['stgs_id'])) return [];
        return $globalConfSrc;
    }

    /**
     * @param string $key
     * @return array
     * getGlobalConfSrcByKey
     */
    public function getGlobalConfSrcByKey(string $key):array
    {
        if(strlen($key) < 1) return [];
        $isFail         = false;
        $globalConfSrc  = $this->DbAuto->getDataOne('SELECT stgs_id, user_id, stgs_key, stgs_value, stgs_desc, stgs_create_time, stgs_update_time FROM '.$this->DbAuto->getTableNameAll('conf_globals').' WHERE stgs_key=\''.$key.'\' AND stgs_delete=0', $isFail);
        if($isFail || !isset($globalConfSrc['stgs_id'])) return [];
        return $globalConfSrc;
    }

    /**
     * @param Page $Page
     * @param array $whereData
     * @return GlobalConfListVO|null
     * getGlobalConfList
     */
    public function getGlobalConfList(Page $Page, array $whereData): ?GlobalConfListVO
    {
        $limitString        = $Page->getLimitString();
        $whereString        = ' WHERE stgs_delete=0 ';
        // 检索条件
        if(count($whereData) > 0)foreach ($whereData as $key => $val){
            switch ($key){
                case GlobalConfListDTO::_stgsId:
                    $whereString    .= (strlen($whereString)>0?' AND ':'').'stgs_id='. intval($val);
                    break;
                case GlobalConfListDTO::_userId:
                    $whereString    .= (strlen($whereString)>0?' AND ':'').'user_id='. intval($val);
                    break;
                case GlobalConfListDTO::_key:
                    $whereString    .= (strlen($whereString)>0?' AND ':'').'stgs_key LIKE \'%'.$this->DbAuto->getRealEscapeString($val).'%\'';
                    break;
            }
        }
        $isFail                 = false;
        $sql                    = 'SELECT SQL_CALC_FOUND_ROWS stgs_id, user_id, stgs_key, stgs_value, stgs_desc, stgs_create_time, stgs_update_time FROM '.$this->DbAuto->getTableNameAll('conf_globals').$whereString.' ORDER BY stgs_id DESC '.$limitString;
        $globalConfRecordList   = $this->DbAuto->getData($sql, $isFail);
        $totalNum               = $this->DbAuto->getDataInt('SELECT FOUND_ROWS() as num', 'num');
        if($isFail) return null;
        $GlobalConfVOList       = [];
        if(CommArray::isForeach($globalConfRecordList))foreach($globalConfRecordList as $globalConfRecord){
            $stgsIdItem         = intval($globalConfRecord['stgs_id']);
            if($stgsIdItem < 1) continue;
            $GlobalConfVO       = $this->getGlobalConfVO($globalConfRecord);
            if(!($GlobalConfVO instanceof GlobalConfVO)) continue;
            $GlobalConfVOList[] = $GlobalConfVO;
        }
        $GlobalConfListVO       = new GlobalConfListVO();
        $GlobalConfListVO->setList($GlobalConfVOList);
        $GlobalConfListVO->setPage($Page->getPageVO($totalNum));
        return $GlobalConfListVO;
    }

    /**
     * @param int $stgsId
     * @return GlobalConfVO|null
     * getGlobalConfInfo
     */
    public function getGlobalConfInfo(int $stgsId): ?GlobalConfVO
    {
        $globalConfRecord   = $this->getGlobalConfSrc($stgsId);
        if(!isset($globalConfRecord['stgs_id'])) return null;
        return $this->getGlobalConfVO($globalConfRecord);
    }

    /**
     * @param array $globalConfRecord
     * @return GlobalConfVO|null
     * getGlobalConfVO
     */
    public function getGlobalConfVO(array $globalConfRecord): ?GlobalConfVO
    {
        $stgsId             = intval($globalConfRecord['stgs_id']??0);
        if($stgsId < 1) return null;
        $GlobalConfVO       = new GlobalConfVO();
        $GlobalConfVO->setStgsId($stgsId);
        $GlobalConfVO->setUserId(intval($globalConfRecord['user_id']));
        $GlobalConfVO->setKey(trim($globalConfRecord['stgs_key']));
        $GlobalConfVO->setValue(trim($globalConfRecord['stgs_value']));
        $GlobalConfVO->setDesc(trim($globalConfRecord['stgs_desc']));
        $GlobalConfVO->setCreateTime(intval($globalConfRecord['stgs_create_time']));
        $GlobalConfVO->setUpdateTime(intval($globalConfRecord['stgs_update_time']));
        return $GlobalConfVO;
    }

    /**
     * @param array $setData
     * @return int
     * globalConfAdd
     */
    public function globalConfAdd(array $setData):int
    {
        if(count($setData) < 1) return 0;
        $setString  = '';
        foreach ($setData as $key => $val){
            switch ($key){
                case GlobalConfAddDTO::_userId:
                    $setString  .= (strlen($setString)>0?',':'').'user_id='.intval($val);
                    break;
                case GlobalConfAddDTO::_key:
                    $setString  .= (strlen($setString)>0?',':'').'stgs_key=\''.$this->DbAuto->getRealEscapeString($val).'\'';
                    break;
                case GlobalConfAddDTO::_value:
                    $setString  .= (strlen($setString)>0?',':'').'stgs_value=\''.$this->DbAuto->getRealEscapeString($val).'\'';
                    break;
                case GlobalConfAddDTO::_desc:
                    $setString  .= (strlen($setString)>0?',':'').'stgs_desc=\''.$this->DbAuto->getRealEscapeString($val).'\'';
                    break;
            }
        }
        if(strlen($setString) < 1) return 0;
        $currTime   = CommTime::getTimeStamp();
        $isFail     = false;
        $sql        = 'INSERT INTO '.$this->DbAuto->getTableNameAll('conf_globals').' SET '.$setString.', stgs_delete=0, stgs_create_time='.$currTime.', stgs_update_time='.$currTime;
        $stgsId     = $this->DbAuto->getDataId($sql, $isFail);
        if($isFail || $stgsId < 1) return 0;
        $this->updateGlobalVersion();
        return $stgsId;
    }

    /**
     * @param int $stgsId
     * @param array $setData
     * @return bool
     * globalConfEdit
     */
    public function globalConfEdit(int $stgsId, array $setData):bool
    {
        if($stgsId < 1 || count($setData) < 1) return false;
        $setString      = '';
        foreach ($setData as $key => $val){
            switch ($key){
                case GlobalConfEditDTO::_userId:
                    $setString  .= (strlen($setString)>0?',':'').'user_id='.intval($val);
                    break;
                case GlobalConfEditDTO::_key:
                    $setString  .= (strlen($setString)>0?',':'').'stgs_key=\''.$this->DbAuto->getRealEscapeString($val).'\'';
                    break;
                case GlobalConfEditDTO::_value:
                    $setString  .= (strlen($setString)>0?',':'').'stgs_value=\''.$this->DbAuto->getRealEscapeString($val).'\'';
                    break;
                case GlobalConfEditDTO::_desc:
                    $setString  .= (strlen($setString)>0?',':'').'stgs_desc=\''.$this->DbAuto->getRealEscapeString($val).'\'';
                    break;
            }
        }
        if(strlen($setString) < 1) return false;
        $currTime   = CommTime::getTimeStamp();
        $isFail     = false;
        $sql        = 'UPDATE '.$this->DbAuto->getTableNameAll('conf_globals').' SET '.$setString.', stgs_update_time='.$currTime.' WHERE stgs_id='.$stgsId.' AND stgs_delete=0';
        $this->DbAuto->getDataNum($sql, $isFail);
        if($isFail) return false;
        if($setData[GlobalConfEditDTO::_key] !== 'version_global_config') $this->updateGlobalVersion();
        return true;
    }

    /**
     * @return bool
     * updateGlobalVersion
     */
    public function updateGlobalVersion():bool
    {
        $currTime   = CommTime::getTimeStamp();
        return $this->DbAuto->getDataNum('UPDATE '.$this->DbAuto->getTableNameAll('conf_globals').' SET stgs_value=stgs_value+1, stgs_update_time='.$currTime.' WHERE stgs_key=\'version_global_config\' AND stgs_delete=0') >= 0;
    }

    /**
     * @return AppGlobalConfVO
     * getAppGlobalConf
     */
    public function getAppGlobalConf():?AppGlobalConfVO
    {
        if(count($this->appGlobalKeyList) < 1) return null;
        $keyListStr         = '';
        foreach ($this->appGlobalKeyList as $keyItem){
            $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($keyItem).'\'';
        }
        $isFail             = false;
        $sql                = 'SELECT stgs_id, stgs_key, stgs_value FROM '.$this->DbAuto->getTableNameAll('conf_globals').' WHERE stgs_key IN('.$keyListStr.') AND stgs_delete=0';
        $list               = $this->DbAuto->getData($sql, $isFail);
        if($isFail || count($list) < 1) return null;
        $AppGlobalConfVO    = new AppGlobalConfVO();
        foreach ($list as $item){
            $stgsId         = $item['stgs_id'];
            if($stgsId < 1) continue;
            $keyItem        = $item['stgs_key'];
            $valueItem      = $item['stgs_value'];
            switch ($keyItem){
                case self::KEY_APP_AD_OPEN:
                    $AppAdOpenVO            = new AppAdOpenVO();
                    $AppAdOpenVO->setStatus(YesOrNoEnum::parseValue($valueItem));
                    $AppGlobalConfVO->setAppAdOpen($AppAdOpenVO);
                    break;
                case self::KEY_SKIT_AD_UNLOCK_SET:
                    $jsonData               = CommJson::decodeArray($valueItem??'[]');
                    $AppAdUnlockSetVO       = new AppAdUnlockSetVO();
                    $AppAdUnlockSetVO->setStatus(YesOrNoEnum::parseValue($jsonData['status']??0));
                    $AppAdUnlockSetVO->setUnlockNum(intval($jsonData['unlockNum']??3));
                    $AppGlobalConfVO->setAppAdUnlockSet($AppAdUnlockSetVO);
                    break;
                case self::KEY_SKIT_VIP_UNLOCK_SET:
                    $jsonData               = CommJson::decodeArray($valueItem??'[]');
                    $AppVipUnlockSetVO      = new AppVipUnlockSetVO();
                    $AppVipUnlockSetVO->setStatus(YesOrNoEnum::parseValue($jsonData['status']??0));
                    $AppGlobalConfVO->setAppVipUnlockSet($AppVipUnlockSetVO);
                    break;
                case self::KEY_SKIT_BUY_UNLOCK_SET:
                    $jsonData               = CommJson::decodeArray($valueItem??'[]');
                    $AppCoinUnlockSetVO     = new AppCoinUnlockSetVO();
                    $AppCoinUnlockSetVO->setStatus(YesOrNoEnum::parseValue($jsonData['status']??0));
                    $AppGlobalConfVO->setAppCoinUnlockSet($AppCoinUnlockSetVO);
                    break;
                case self::KEY_APP_PAY_TEXT_RECHARGE:
                    $AppPayRechargeTextVO   = new AppPayRechargeTextVO();
                    $AppPayRechargeTextVO->setText($valueItem);
                    $AppGlobalConfVO->setAppPayRechargeText($AppPayRechargeTextVO);
                    break;
                case self::KEY_APP_PAY_VIP:
                    $AppPayVipVO            = new AppPayVipVO();
                    $AppPayVipVO->setStatus(YesOrNoEnum::parseValue($valueItem));
                    $AppGlobalConfVO->setAppPayVip($AppPayVipVO);
                    break;
                case self::KEY_APP_PAY_RECHARGE:
                    $AppPayRechargeVO       = new AppPayRechargeVO();
                    $AppPayRechargeVO->setStatus(YesOrNoEnum::parseValue($valueItem));
                    $AppGlobalConfVO->setAppPayRecharge($AppPayRechargeVO);
                    break;
                case self::KEY_APP_BANNER_SHOW_STYLE:
                    $AppBannerShowStyleVO   = new AppBannerShowStyleVO();
                    $AppBannerShowStyleVO->setStyle(BannerShowStyleEnum::parseValue($valueItem));
                    $AppGlobalConfVO->setAppBannerShowStyle($AppBannerShowStyleVO);
                    break;
		        case self::KEY_APP_TASK_STATUS:
                    $AppTaskConfVO          = new AppTaskConfVO();
                    $AppTaskConfVO->setStatus(YesOrNoEnum::parseValue($valueItem));
                    $AppGlobalConfVO->setAppTaskConf($AppTaskConfVO);
		            break;
                case self::KEY_APP_AD_MOB_CONF:
                    $jsonData               = CommJson::decodeArray($valueItem??'[]');
                    $AppAdMobConfVO         = new AppAdMobConfVO();
                    $AppAdMobVOAndroid      = new AppAdMobVO();
                    $AppAdMobVOAndroid->setVideoAdId($jsonData['android']['videoAdId']??'');
                    $AppAdMobVOAndroid->setTaskAdId($jsonData['android']['taskAdId']??'');
                    $AppAdMobVOAndroid->setRmdAdId($jsonData['android']['rmdAdId']??'');
                    $AppAdMobVOIos          = new AppAdMobVO();
                    $AppAdMobVOIos->setVideoAdId($jsonData['ios']['videoAdId']??'');
                    $AppAdMobVOIos->setTaskAdId($jsonData['ios']['taskAdId']??'');
                    $AppAdMobVOIos->setRmdAdId($jsonData['ios']['rmdAdId']??'');
                    $AppAdMobConfVO->setAndroid($AppAdMobVOAndroid);
                    $AppAdMobConfVO->setIos($AppAdMobVOIos);
                    $AppGlobalConfVO->setAppAdMobConf($AppAdMobConfVO);
                    break;
                case self::KEY_APP_RECHARGE_RETAIN:
                    $jsonData                   = CommJson::decodeArray($valueItem??'[]');
                    $AppRechargeRetainVO        = new AppRechargeRetainVO();
                    $AppRechargeRetainItemYesVO = new AppRechargeRetainItemVO();
                    $AppRechargeRetainItemYesVO->setStatus(YesOrNoEnum::parseValue($jsonData['payYes']['status']??0));
                    $AppRechargeRetainItemYesVO->setTitle(trim($jsonData['payYes']['title']??''));
                    $AppRechargeRetainItemYesVO->setDesc(trim($jsonData['payYes']['desc']??''));
                    $AppRechargeRetainItemYesVO->setDayNum(intval($jsonData['payYes']['dayNum']??0));
                    $AppRechargeRetainItemYesVO->setPgspIdList($jsonData['payYes']['pgspIdList']??[]);
                    $AppRechargeRetainItemNoVO  = new AppRechargeRetainItemVO();
                    $AppRechargeRetainItemNoVO->setStatus(YesOrNoEnum::parseValue($jsonData['payNo']['status']??0));
                    $AppRechargeRetainItemNoVO->setTitle(trim($jsonData['payNo']['title']??''));
                    $AppRechargeRetainItemNoVO->setDesc(trim($jsonData['payNo']['desc']??''));
                    $AppRechargeRetainItemNoVO->setDayNum(intval($jsonData['payNo']['dayNum']??0));
                    $AppRechargeRetainItemNoVO->setPgspIdList($jsonData['payNo']['pgspIdList']??[]);
                    $AppRechargeRetainVO->setPayYes($AppRechargeRetainItemYesVO);
                    $AppRechargeRetainVO->setPayNo($AppRechargeRetainItemNoVO);
                    $AppGlobalConfVO->setAppRechargeRetain($AppRechargeRetainVO);
                    break;
                case self::KEY_APP_RMD_AD_POS:
                    $jsonData                   = CommJson::decodeArray($valueItem??'[]');
                    $AppRmdAdPosVO              = new AppRmdAdPosVO();
                    $AppRmdAdPosVO->setStatus(YesOrNoEnum::parseValue($jsonData['status']??0));
                    $AppRmdAdPosVO->setPosList($jsonData['posList']??[]);
                    $AppGlobalConfVO->setAppRmdAdPos($AppRmdAdPosVO);
                    break;
                case self::KEY_APP_REVIEW_FEEDBACK:
                    $jsonData                   = CommJson::decodeArray($valueItem??'[]');
                    $AppReviewFeedbackVO        = new AppReviewFeedbackVO();
                    $AppReviewFeedbackVO->setStatus(YesOrNoEnum::parseValue($jsonData['status']??0));
                    $AppReviewFeedbackVO->setPlaySeriesNum(intval($jsonData['playSeriesNum']??0));
                    $AppReviewFeedbackVO->setStarNum(intval($jsonData['starNum']??0));
                    $AppReviewFeedbackVO->setRewardNum(intval($jsonData['rewardNum']??0));
                    $AppReviewFeedbackVO->setRewardTime(intval($jsonData['rewardTime']??0));
                    $AppReviewFeedbackVO->setTitle(trim($jsonData['title']??''));
                    $AppReviewFeedbackVO->setDesc(trim($jsonData['desc']??''));
                    $AppGlobalConfVO->setAppReviewFeedback($AppReviewFeedbackVO);
                    break;
                case self::KEY_APP_DESKTOP_REWARD:
                    $jsonData                   = CommJson::decodeArray($valueItem??'[]');
                    $AppDesktopRewardVO         = new AppDesktopRewardVO();
                    $AppDesktopRewardVO->setStatus(YesOrNoEnum::parseValue($jsonData['status']??0));
                    $AppDesktopRewardVO->setRewardNum(intval($jsonData['rewardNum']??0));
                    $AppDesktopRewardVO->setRewardTime(intval($jsonData['rewardTime']??0));
                    $AppGlobalConfVO->setAppDesktopReward($AppDesktopRewardVO);
                    break;
                case self::KEY_APP_AD_SPLIT_TIME:
                    $appAdSplitTime             = is_array($valueItem)?0:intval($valueItem);
                    $AppAdSplitTimeVO           = new AppAdSplitTimeVO();
                    $AppAdSplitTimeVO->setAdSplitTime($appAdSplitTime);
                    $AppGlobalConfVO->setAppAdSplitTime($AppAdSplitTimeVO);
                    break;
                case self::KEY_APP_AD_DAY_LIMIT:
                    $appAdDayLimit              = is_array($valueItem)?0:intval($valueItem);
                    $AppAdDayLimitVO            = new AppAdDayLimitVO();
                    $AppAdDayLimitVO->setAdDayLimit($appAdDayLimit);
                    $AppGlobalConfVO->setAppAdDayLimit($AppAdDayLimitVO);
                    break;
                case self::KEY_APP_AD_MAX_CONF:
                    $jsonData               = CommJson::decodeArray($valueItem??'[]');
                    $AppAdMaxConfVO         = new AppAdMaxConfVO();
                    $AppAdMaxVOAndroid      = new AppAdMaxVO();
                    $AppAdMaxVOAndroid->setVideoAdId($jsonData['android']['videoAdId']??'');
                    $AppAdMaxVOAndroid->setTaskAdId($jsonData['android']['taskAdId']??'');
                    $AppAdMaxVOAndroid->setRmdAdId($jsonData['android']['rmdAdId']??'');
                    $AppAdMaxVOIos          = new AppAdMaxVO();
                    $AppAdMaxVOIos->setVideoAdId($jsonData['ios']['videoAdId']??'');
                    $AppAdMaxVOIos->setTaskAdId($jsonData['ios']['taskAdId']??'');
                    $AppAdMaxVOIos->setRmdAdId($jsonData['ios']['rmdAdId']??'');
                    $AppAdMaxConfVO->setAndroid($AppAdMaxVOAndroid);
                    $AppAdMaxConfVO->setIos($AppAdMaxVOIos);
                    $AppGlobalConfVO->setAppAdMaxConf($AppAdMaxConfVO);
                    break;
            }
        }
        return $AppGlobalConfVO;
    }

    /**
     * @param $setData
     * @return bool
     * setAppGlobalConf
     */
    public function setAppGlobalConf($setData):bool
    {
        if(count($setData) < 1 || count($this->appGlobalKeyList) < 1) return false;
        $keyListStr         = '';
        $setString          = '';
        foreach ($setData as $key => $item){
            switch ($key){
                case self::KEY_APP_AD_OPEN:
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_APP_AD_OPEN).'\' THEN '.intval($item);
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
                case self::KEY_SKIT_AD_UNLOCK_SET:
                    if(!is_array($item) || count($item) < 1) return false;
                    $jsonStr        = CommJson::encodeArray($item);
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_SKIT_AD_UNLOCK_SET).'\' THEN \''.$this->DbAuto->getRealEscapeString($jsonStr).'\'';
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
                case self::KEY_SKIT_VIP_UNLOCK_SET:
                    if(!is_array($item) || count($item) < 1) return false;
                    $jsonStr        = CommJson::encodeArray($item);
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_SKIT_VIP_UNLOCK_SET).'\' THEN \''.$this->DbAuto->getRealEscapeString($jsonStr).'\'';
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
                case self::KEY_SKIT_BUY_UNLOCK_SET:
                    if(!is_array($item) || count($item) < 1) return false;
                    $jsonStr        = CommJson::encodeArray($item);
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_SKIT_BUY_UNLOCK_SET).'\' THEN \''.$this->DbAuto->getRealEscapeString($jsonStr).'\'';
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
                case self::KEY_APP_PAY_TEXT_RECHARGE:
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_APP_PAY_TEXT_RECHARGE).'\' THEN \''.$this->DbAuto->getRealEscapeString($item).'\'';
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
                case self::KEY_APP_PAY_VIP:
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_APP_PAY_VIP).'\' THEN '.intval($item);
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
                case self::KEY_APP_PAY_RECHARGE:
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_APP_PAY_RECHARGE).'\' THEN '.intval($item);
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
                case self::KEY_APP_BANNER_SHOW_STYLE:
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_APP_BANNER_SHOW_STYLE).'\' THEN '.intval($item);
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
                case self::KEY_APP_TASK_STATUS:
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_APP_TASK_STATUS).'\' THEN '.intval($item);
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
                case self::KEY_APP_AD_MOB_CONF:
                    if(!is_array($item) || count($item) < 1) return false;
                    $jsonStr        = CommJson::encodeArray($item);
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_APP_AD_MOB_CONF).'\' THEN \''.$this->DbAuto->getRealEscapeString($jsonStr).'\'';
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
                case self::KEY_APP_RECHARGE_RETAIN:
                    if(!is_array($item) || count($item) < 1) return false;
                    $jsonStr        = CommJson::encodeArray($item);
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_APP_RECHARGE_RETAIN).'\' THEN \''.$this->DbAuto->getRealEscapeString($jsonStr).'\'';
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
                case self::KEY_APP_RMD_AD_POS:
                    if(!is_array($item) || count($item) < 1) return false;
                    $jsonStr        = CommJson::encodeArray($item);
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_APP_RMD_AD_POS).'\' THEN \''.$this->DbAuto->getRealEscapeString($jsonStr).'\'';
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
                case self::KEY_APP_REVIEW_FEEDBACK:
                    if(!is_array($item) || count($item) < 1) return false;
                    $jsonStr        = CommJson::encodeArray($item);
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_APP_REVIEW_FEEDBACK).'\' THEN \''.$this->DbAuto->getRealEscapeString($jsonStr).'\'';
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
                case self::KEY_APP_DESKTOP_REWARD:
                    if(!is_array($item) || count($item) < 1) return false;
                    $jsonStr        = CommJson::encodeArray($item);
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_APP_DESKTOP_REWARD).'\' THEN \''.$this->DbAuto->getRealEscapeString($jsonStr).'\'';
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
                case self::KEY_APP_AD_SPLIT_TIME:
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_APP_AD_SPLIT_TIME).'\' THEN '.intval($item);
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
                case self::KEY_APP_AD_DAY_LIMIT:
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_APP_AD_DAY_LIMIT).'\' THEN '.intval($item);
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
                case self::KEY_APP_AD_MAX_CONF:
                    if(!is_array($item) || count($item) < 1) return false;
                    $jsonStr        = CommJson::encodeArray($item);
                    $setString      .= ' WHEN \''.$this->DbAuto->getRealEscapeString(self::KEY_APP_AD_MAX_CONF).'\' THEN \''.$this->DbAuto->getRealEscapeString($jsonStr).'\'';
                    $keyListStr     .= (strlen($keyListStr)>0?',':'').'\''.$this->DbAuto->getRealEscapeString($key).'\'';
                    break;
            }
        }
        if(strlen($setString) < 1 || strlen($keyListStr) < 1) return false;
        $isFail     = false;
        $currTime   = CommTime::getTimeStamp();
        $sql        = 'UPDATE '.$this->DbAuto->getTableNameAll('conf_globals').' SET stgs_value=CASE stgs_key '.$setString.' END, stgs_update_time='.$currTime.' WHERE stgs_key IN('.$keyListStr.') AND stgs_delete=0';
        $resNum     = $this->DbAuto->getDataNum($sql, $isFail);
        if($isFail) return false;
        if($resNum > 0) $this->updateGlobalVersion();
        return true;
    }

    /**
     * @param int $style
     * @return bool
     * checkAppBannerShowStyle
     */
    public function checkAppBannerShowStyle(int $style):bool
    {
        if($style === BannerShowStyleEnum::BANNER_SHOW_STYLE_ONE){
            $num    = $this->DbAuto->getDataInt('SELECT COUNT(banr_id) AS num FROM '.$this->DbAuto->getTableNameAll('banner_record').' WHERE banr_delete=0 AND banr_status='.YesOrNoEnum::YES_OR_NO_YES.' AND banr_image=\'\'', 'num');
            return $num < 1;
        }else if($style === BannerShowStyleEnum::BANNER_SHOW_STYLE_TWO){
            $num    = $this->DbAuto->getDataInt('SELECT COUNT(banr_id) AS num FROM '.$this->DbAuto->getTableNameAll('banner_record').' WHERE banr_delete=0 AND banr_status='.YesOrNoEnum::YES_OR_NO_YES.' AND banr_image_two=\'\'', 'num');
            return $num < 1;
        }else{
            return false;
        }
    }
}